package com.jzg.jcptadmin.ui.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.Utils.ScreenUtils;
import com.jzg.jcptadmin.adpter.HistoricalPriceAdapter;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.jcptadmin.ui.EvaluationActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jzg on 2016/2/29.
 */
public class HistoricalPriceFragment extends Fragment {
    @Bind(R.id.text_area)
    TextView textArea;
    @Bind(R.id.text_appraiser)
    TextView textAppraiser;
    @Bind(R.id.text_price)
    TextView textPrice;
    @Bind(R.id.text_time)
    TextView textTime;
    @Bind(R.id.list)
    ListView list;
    @Bind(R.id.ll_guzhi)
    LinearLayout llGuzhi;
    private View rootView;
    private EvaluationActivity evaluationActivity;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = View.inflate(getActivity(), R.layout.historical_price_layout, null);
        ButterKnife.bind(this, rootView);
        //设置表格标题的背景颜色
        llGuzhi.setBackgroundColor(Color.rgb(71, 144, 239));
        ViewGroup.LayoutParams params = list.getLayoutParams();
        params.width = RadioGroup.LayoutParams.MATCH_PARENT;
       params.height = ScreenUtils.getScreenWidth(getActivity()) * 3 / 4;
        //params.height = RadioGroup.LayoutParams.WRAP_CONTENT;
        list.setLayoutParams(params);
        initData();
        return rootView;
    }

    private void initData() {
        evaluationActivity = (EvaluationActivity)getActivity();
        CarDetails details = evaluationActivity.getData();
       List<CarDetails.TaskListData> listData=  details.getHistoryTaskList();
        if(listData!=null){
            if(listData.size()==0){
                CarDetails.TaskListData taskListData = new CarDetails.TaskListData();
                taskListData.setHAppraiserName("--");
                taskListData.setHCityName("--");
                taskListData.setHDateTime("--");
                taskListData.setB2CPrice("--");
                taskListData.setC2BPrice("--");
//                taskListData.setHPrice("收321" + "\n" + "售345");
                listData.add(taskListData);
            }
            HistoricalPriceAdapter historicalPriceAdapter = new HistoricalPriceAdapter(listData,getContext());
            list.setAdapter(historicalPriceAdapter);
        }else{
            List<CarDetails.TaskListData> listData1 = new ArrayList<>();
            CarDetails.TaskListData taskListData = new CarDetails.TaskListData();
            taskListData.setHAppraiserName("--");
            taskListData.setHCityName("--");
            taskListData.setHDateTime("--");
            taskListData.setB2CPrice("--");
            taskListData.setC2BPrice("--");
//            taskListData.setHPrice("收321"+"\n"+"售345");
            listData1.add(taskListData);
            HistoricalPriceAdapter historicalPriceAdapter = new HistoricalPriceAdapter(listData1,getContext());
            list.setAdapter(historicalPriceAdapter);
        }

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
